package com.lincoln.cloud.servercenter.bean;

import com.lincoln.cloud.servercenter.interfaces.BaseServerInfo;
import com.lincoln.framework.interfaces.MsgNoDeviceInfo;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * 消费者信息
 *
 * @author lincoln
 */
@Data
public class ServerInfo extends MsgNoDeviceInfo<Integer> implements BaseServerInfo {
    private static final Logger logger = LoggerFactory.getLogger(ServerInfo.class);

    public static final int DEVICE_TYPE = -1;
    public static final int PROTOCOL_TYPE = -1;
    /**
     * 服务器id
     */
    private Integer id;

    /**
     * 作者
     */
    private String author;

    /**
     * 服务器别名
     */
    private String name;

    /**
     * http服务端口号
     */
    private int httpPort;

    /**
     * 设备号
     */
    private Integer deviceType;

    /**
     * 协议号
     */
    private Integer protocolType;

    @Override
    public boolean isLogin() {
        return id != null && ServerCenterContext.serverPool().findById(id) != null;
    }

    @Override
    public boolean login() {
        ServerCenterContext.serverPool().addServer(this);
        return super.login();
    }

    @Override
    public boolean logout() {
        if (ServerCenterContext.serverPool().findById(getId()) != null) {
            ServerCenterContext.serverPool().deleteServer(getPrimaryKey());
        }
        return true;
    }

    @Override
    public Integer getPrimaryKey() {
        return id;
    }

    @Override
    public void setPrimaryKey(int id) {
        this.id = id;
    }

    @Override
    public Integer getDeviceType() {
        return deviceType;
    }

    @Override
    public Integer getProtocolType() {
        return protocolType;
    }

    @Override
    public Date getFirstContact() {
        return null;
    }

    @Override
    public void setFirstContact(Date firstContact) {

    }

    @Override
    public Date getLastContact() {
        return null;
    }

    @Override
    public void setLastContact(Date firstContact) {

    }

    @Override
    public String getIntroduce() {
        return null;
    }

    @Override
    public void setIntroduce(String introduce) {

    }
}
